import java.io.*;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class 合并果子 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        PriorityQueue<Integer> heap = new PriorityQueue<>();

        for (int i = 0; i < n; i++) {
            heap.add(in.nextInt());
        }
        int ans = 0;
        while (heap.size() > 1) {
            int cur = heap.poll() + heap.poll();
            ans += cur;
            heap.add(cur);
        }
        out.println(ans);
        out.close();
    }




    public static class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
    }
}
